package com.lottery.dao.qiuqiu.wealthDao;

import com.lottery.entity.AccountTransaction;
import com.lottery.entity.Bettinginfo;
import com.lottery.entity.Rebate;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * 账户流水表Dao;
 */
public interface AccountTransactionDao {
    /**
     * 查询所有
     */
    List<AccountTransaction> selectAccountTransactionList();

    /**
     * 根据主键ID查询
     */
    AccountTransaction selectAccountTransactionById(@Param(value = "id") int id);

    /**
     * 根据账户id查询
     */
    List<AccountTransaction> selectAccountTransactionByAccountId(@Param(value = "accountId") int accountId);

    /**
     * 根据状态查询
     */
    List<AccountTransaction> selectAccountTransactionBystate(@Param(value = "state") int state);

    /**
     * 添加
     */
    void insertAccountTransaction(AccountTransaction accounttransaction);

    /**
     * 修改
     */
    void updateAccountTransaction(AccountTransaction accounttransaction);

    /**
     * 根据订单号来查询用户信息
     */
    AccountTransaction selectByorderId(String orderId);

    int selectTransactionCountById(int accountId);

    /**
     * 分页查询
     *
     * @param pageSize
     * @return
     */
    List<AccountTransaction> selectAccountTransactionByAccountIdLimit(@Param(value = "accountId") int accountId,
                                                                      @Param(value = "types") int types, @Param(value = "startPage") int startPage,
                                                                      @Param(value = "pageSize") int pageSize);

    /**
     * 根据userid查询分成金额
     */
    String selectTransactionMoney(int userId);

    /**
     * 查询提现流水状态接口
     */
    List<AccountTransaction> queryOrderStatus(Map<String, Integer> params);

    /**
     * 返点操作
     */
    List<Rebate> queryRebate(int startCount);

    int getCashTimes(int accountId);

    int totalWithDrawWealth(Map<String, Object> params);

    int totalRechargeWealth(Map<String, Object> params);

    int selectSumAmount(Map<String, Object> params);

    int selectSumAmountWithDrow(Map<String, Object> params);

    List<AccountTransaction> selectTranstionList(Map<String, Object> params);

    @Update("update account_transaction set state = 4 where id = #{id} ")
    void cancelWithdrawById(@Param(value = "id") Integer id) throws Exception;

    @Delete("delete from account_transaction where order_id = #{k}")
    void deleteRecordByOrderId(String k) throws Exception;

    List<AccountTransaction> selectInfoByAccountId(Map<String, Object> accoutParams);

    List<AccountTransaction> selectMypurseRecord(Map<String, Object> params);

    @Select("SELECT IFNULL(sum(transaction_money),0) from account_transaction where transaction_type = 7 and agency_mark = #{agencyMark}  and DATE_FORMAT(transaction_date,'%Y-%m') = #{time}")
    double searchProxyIncome(@Param(value = "time") String time, @Param(value = "agencyMark") String agencyMark);
}
